/*
package com.gitee.wsl.compose.modifier.style

import android.annotation.SuppressLint
import android.graphics.BlurMaskFilter
import android.util.Log
import androidx.annotation.IntDef
import androidx.annotation.RestrictTo
import androidx.compose.animation.animateColor
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.DrawModifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.RoundRect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.NativePaint
import androidx.compose.ui.graphics.Paint
import androidx.compose.ui.graphics.PaintingStyle
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.ContentDrawScope
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.gitee.wsl.compose.modifier.ModifierStyleScope

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@IntDef(
    LightSource.LEFT_TOP,
    LightSource.LEFT_BOTTOM,
    LightSource.RIGHT_TOP,
    LightSource.RIGHT_BOTTOM
)
@Retention(AnnotationRetention.SOURCE)
annotation class LightSource {
    companion object {
        const val LEFT_TOP = 0
        const val LEFT_BOTTOM = 1
        const val RIGHT_TOP = 2
        const val RIGHT_BOTTOM = 3

        const val DEFAULT = LEFT_TOP

        fun opposite( lightSource:Int): Int {
            return when (lightSource) {
                LEFT_TOP -> RIGHT_BOTTOM
                RIGHT_TOP -> LEFT_BOTTOM
                LEFT_BOTTOM -> RIGHT_TOP
                RIGHT_BOTTOM -> LEFT_TOP
                else -> {-1}
            }
        }
    }

}

object  ConstantColor{

    val NeumorphismLightBackgroundColor = Color(0xFFECF0F3)

    val NeumorphismDarkBackgroundColor = Color(0xFF303234)

    */
/*Light theme shadow color.*//*

    const val THEME_LIGHT_COLOR_SHADOW_LIGHT = 0xffffffff

    const val THEME_LIGHT_COLOR_SHADOW_DARK = 0xffd9d9d9

    */
/*Dart theme shadow color.*//*

    const val THEME_DARK_COLOR_SHADOW_LIGHT = 0xff2c2c2c

    const val THEME_DARK_COLOR_SHADOW_DARK = 0xff111111

    val backgroundColorOrange = Color(0xfffd8f31)
    val shadowColorLightOrange = Color(0xffffa438)
    val shadowColorDarkOrange = Color(0xffd77a2a)


}

object Shape{

    const val Circle = 0

    const val Rectangle = 1
}

*/
/**
 * 背景阴影扩展函数
 *//*

internal fun Modifier.backgroundShadow(
    shadowColorLight: Color = Color(ConstantColor.THEME_LIGHT_COLOR_SHADOW_LIGHT),
    shadowColorDark: Color = Color(ConstantColor.THEME_LIGHT_COLOR_SHADOW_DARK),
    blurRadius:Float = 8f,
    lightSource: Int = LightSource.DEFAULT,
    offset:Float = 10f,
    cornerRadius: Dp = 0.dp,
    shape:Int = Shape.Rectangle,
    borderWidth : Dp = 20.dp,//Shape.Circle中作为圆环宽度
) = then(object : DrawModifier {
    override fun ContentDrawScope.draw() {

        val TAG = "Modifier.backgroundShadow"
        Log.i(TAG,"backgroundShadow shadowColorLight:$shadowColorLight shadowColorDark:$shadowColorDark blurRadius:$blurRadius lightSource:$lightSource offset:$offset cornerRadius:$cornerRadius size:${size.width}-${size.height}")
        //浅色阴影画笔
        val paintShadowLight = Paint().also { paint: androidx.compose.ui.graphics.Paint ->
            paint.asFrameworkPaint() //将自定义的绘制操作转换成底层渲染引擎能够理解的渲染描述对象，从而实现更加高效和灵活的绘制操作。
                .also {nativePaint: NativePaint ->
                    nativePaint.isAntiAlias = true //设置抗锯齿
                    nativePaint.isDither = true //开启防抖
                    nativePaint.color = shadowColorLight.toArgb() //设置画笔颜色
                    if (offset>0) nativePaint.maskFilter = BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.NORMAL) //设置模糊滤镜效果
                }
        }
        //浅色阴影在光源方向的偏移量
        val backgroundShadowLightOffset: Offset = when(lightSource){
            LightSource.LEFT_TOP -> Offset(-offset,-offset)
            LightSource.LEFT_BOTTOM -> Offset(-offset,offset)
            LightSource.RIGHT_TOP -> Offset(offset, -offset)
            LightSource.RIGHT_BOTTOM -> Offset(offset, offset)
            else -> {
                Offset(0f,0f)
            }
        }
        //深色阴影画笔
        val paintShadowDark = Paint().also { paint: androidx.compose.ui.graphics.Paint ->
            paint.asFrameworkPaint() //将自定义的绘制操作转换成底层渲染引擎能够理解的渲染描述对象，从而实现更加高效和灵活的绘制操作。
                .also {nativePaint: NativePaint ->
                    nativePaint.isAntiAlias = true //设置抗锯齿
                    nativePaint.isDither = true //开启防抖
                    nativePaint.color = shadowColorDark.toArgb() //设置画笔颜色
                    if (offset>0)nativePaint.maskFilter = BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.NORMAL) //设置模糊滤镜效果
                }
        }
        //深色阴影在光源方向的偏移量
        val backgroundShadowDarkOffset: Offset = when(LightSource.opposite(lightSource)){
            LightSource.LEFT_TOP -> Offset(-offset,-offset)
            LightSource.LEFT_BOTTOM -> Offset(-offset,offset)
            LightSource.RIGHT_TOP -> Offset(offset, -offset)
            LightSource.RIGHT_BOTTOM -> Offset(offset, offset)
            else -> {
                Offset(0f,0f)
            }
        }


        drawIntoCanvas {

            //画布平移绘制浅色阴影
            it.save()
            it.translate(backgroundShadowLightOffset.x,backgroundShadowLightOffset.y)
            when(shape){
                Shape.Circle ->{
                    paintShadowLight.style = PaintingStyle.Stroke
                    paintShadowLight.strokeWidth = borderWidth.toPx()
                    it.drawCircle(
                        Offset(this.size.width/2,this.size.height/2),
                        (this.size.width - borderWidth.toPx()  )/2,
                        paintShadowLight
                    )
                }
               Shape.Rectangle ->{
                    it.drawRoundRect(
                        0f,
                        0f,
                        this.size.width,
                        this.size.height,
                        cornerRadius.toPx(),
                        cornerRadius.toPx(),
                        paintShadowLight
                    )
                }
            }
            it.restore()
            //画布平移绘制深色阴影
            it.save()
            it.translate(backgroundShadowDarkOffset.x,backgroundShadowDarkOffset.y)
            when(shape){
                Shape.Circle ->{
                    paintShadowDark.style = PaintingStyle.Stroke
                    paintShadowDark.strokeWidth = borderWidth.toPx()
                    it.drawCircle(
                        Offset(this.size.width/2,this.size.height/2),
                        (this.size.width - borderWidth.toPx() )/2,
                        paintShadowDark
                    )
                }
                Shape.Rectangle ->{
                    it.drawRoundRect(
                        0f,
                        0f,
                        this.size.width,
                        this.size.height,
                        cornerRadius.toPx(),
                        cornerRadius.toPx(),
                        paintShadowDark
                    )
                }
            }
            it.restore()
        }

        drawContent()
    }
})
*/
/**
 * 前景阴影扩展函数
 *//*

internal fun Modifier.foregroundShadow(
    shadowColorLight: Color = Color(ConstantColor.THEME_LIGHT_COLOR_SHADOW_LIGHT),
    shadowColorDark: Color = Color(ConstantColor.THEME_LIGHT_COLOR_SHADOW_DARK),
    blurRadius:Float = 8f,
    lightSource: Int = LightSource.DEFAULT,
    offset:Float = 22f,
    cornerRadius: Dp = 0.dp,
)  = then(object : DrawModifier {
    override fun ContentDrawScope.draw() {
        drawContent()


        val TAG = "Modifier.backgroundShadow"
        Log.i(TAG,"backgroundShadow shadowColorLight:$shadowColorLight shadowColorDark:$shadowColorDark blurRadius:$blurRadius lightSource:$lightSource offset:$offset cornerRadius:$cornerRadius size:${size.width}-${size.height}")
        //浅色阴影画笔
        val paintShadowLight = Paint().also { paint: androidx.compose.ui.graphics.Paint ->
            paint.asFrameworkPaint() //将自定义的绘制操作转换成底层渲染引擎能够理解的渲染描述对象，从而实现更加高效和灵活的绘制操作。
                .also {nativePaint: NativePaint ->
                    nativePaint.isAntiAlias = true //设置抗锯齿
                    nativePaint.isDither = true //开启防抖
                    nativePaint.color = shadowColorLight.toArgb() //设置画笔颜色
                    nativePaint.style = android.graphics.Paint.Style.STROKE
                    nativePaint.strokeWidth = offset
                    if (offset>0)nativePaint.maskFilter = BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.NORMAL) //设置模糊滤镜效果
                }
        }
        //浅色阴影在光源方向的偏移量
        val backgroundShadowLightOffset: Offset = when(LightSource.opposite(lightSource)){
            LightSource.LEFT_TOP -> Offset(offset,offset)
            LightSource.LEFT_BOTTOM -> Offset(offset,-offset)
            LightSource.RIGHT_TOP -> Offset(-offset, offset)
            LightSource.RIGHT_BOTTOM -> Offset(-offset, -offset)
            else -> {
                Offset(0f,0f)
            }
        }
        //深色阴影画笔
        val paintShadowDark = Paint().also { paint: androidx.compose.ui.graphics.Paint ->
            paint.asFrameworkPaint() //将自定义的绘制操作转换成底层渲染引擎能够理解的渲染描述对象，从而实现更加高效和灵活的绘制操作。
                .also {nativePaint: NativePaint ->
                    nativePaint.isAntiAlias = true //设置抗锯齿
                    nativePaint.isDither = true //开启防抖
                    nativePaint.color = shadowColorDark.toArgb() //设置画笔颜色
                    nativePaint.style = android.graphics.Paint.Style.STROKE
                    nativePaint.strokeWidth = offset //设置描边宽度
                    if (offset>0)nativePaint.maskFilter = BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.NORMAL) //设置模糊滤镜效果
                }
        }
        //深色阴影在光源方向的偏移量
        val backgroundShadowDarkOffset: Offset = when(lightSource){
            LightSource.LEFT_TOP -> Offset(offset,offset)
            LightSource.LEFT_BOTTOM -> Offset(offset,-offset)
            LightSource.RIGHT_TOP -> Offset(-offset, offset)
            LightSource.RIGHT_BOTTOM -> Offset(-offset, -offset)
            else -> {
                Offset(0f,0f)
            }
        }


        drawIntoCanvas {
            Log.e("draw","dark offset:$offset x:${backgroundShadowDarkOffset.x} y:${backgroundShadowDarkOffset.y} width:${this.size.width} height:${this.size.height} ")
            Log.e("draw","light offset:$offset x:${backgroundShadowLightOffset.x} y:${backgroundShadowLightOffset.y} width:${this.size.width} height:${this.size.height} ")
            //绘制深色阴影
            it.save()
            val pathShadowDark = Path().also { path ->
                path.moveTo(0f, 0f)
                path.addRoundRect(RoundRect(0f, 0f, this.size.width , this.size.height, cornerRadius.toPx(), cornerRadius.toPx()))
            }
            it.clipPath(pathShadowDark)
            it.translate(backgroundShadowDarkOffset.x,backgroundShadowDarkOffset.y)
            it.drawRoundRect(
                -offset,
                -offset,
                this.size.width + offset,
                this.size.height + offset,
                cornerRadius.toPx(),
                cornerRadius.toPx(),
                paintShadowDark
            )
            it.restore()
            //绘制浅色阴影
            it.save()
            val pathShadowLight = Path().also { path ->
                path.moveTo(0f, 0f)
                path.addRoundRect(RoundRect(0f, 0f, this.size.width, this.size.height, cornerRadius.toPx(), cornerRadius.toPx()))
            }
            it.clipPath(pathShadowLight)
            it.translate(backgroundShadowLightOffset.x,backgroundShadowLightOffset.y)
            it.drawRoundRect(
                -offset,
                -offset,
                this.size.width + offset,
                this.size.height + offset,
                cornerRadius.toPx(),
                cornerRadius.toPx(),
                paintShadowLight
            )
            it.restore()

        }

    }
})

fun ModifierStyleScope.foregroundShadow(
    shadowColorLight: Color = Color(ConstantColor.THEME_LIGHT_COLOR_SHADOW_LIGHT),
    shadowColorDark: Color = Color(ConstantColor.THEME_LIGHT_COLOR_SHADOW_DARK),
    blurRadius:Float = 8f,
    lightSource: Int = LightSource.DEFAULT,
    offset:Float = 22f,
    cornerRadius: Dp = 0.dp,
) {
   modifier = modifier.foregroundShadow(shadowColorLight, shadowColorDark, blurRadius, lightSource, offset, cornerRadius)
}

fun ModifierStyleScope.backgroundShadow(
    shadowColorLight: Color = Color(ConstantColor.THEME_LIGHT_COLOR_SHADOW_LIGHT),
    shadowColorDark: Color = Color(ConstantColor.THEME_LIGHT_COLOR_SHADOW_DARK),
    blurRadius:Float = 8f,
    lightSource: Int = LightSource.DEFAULT,
    offset:Float = 10f,
    cornerRadius: Dp = 0.dp,
    shape:Int = Shape.Rectangle,
    borderWidth : Dp = 20.dp,//Shape.Circle中作为圆环宽度
) {
    modifier = modifier.backgroundShadow(shadowColorLight, shadowColorDark, blurRadius, lightSource, offset, cornerRadius, shape, borderWidth)
}


@SuppressLint("ModifierFactoryUnreferencedReceiver")
internal fun Modifier.drawAnimatedColoredShadow(
    initialColor : Color,
    targetColor : Color,
    durationMillis : Int = 2000,
    alpha: Float = 0.2f,
    borderRadius: Dp = 0.dp,
    shadowRadius: Dp = 20.dp,
    offsetY: Dp = 0.dp,
    offsetX: Dp = 0.dp
): Modifier = composed {
    val infiniteTransition = rememberInfiniteTransition(label = "")

    val color by infiniteTransition.animateColor(
        initialValue = initialColor,
        targetValue = targetColor,
        animationSpec = infiniteRepeatable(
            animation = tween(durationMillis, easing = LinearEasing),
            repeatMode = RepeatMode.Reverse
        ), label = ""
    )
    drawColoredShadow(
        color,
        alpha,
        borderRadius, shadowRadius, offsetY, offsetX
    )

}

fun ModifierStyleScope.drawAnimatedColoredShadow(
    initialColor : Color,
    targetColor : Color,
    durationMillis : Int = 2000,
    alpha: Float = 0.2f,
    borderRadius: Dp = 0.dp,
    shadowRadius: Dp = 20.dp,
    offsetY: Dp = 0.dp,
    offsetX: Dp = 0.dp
){
    modifier = modifier.drawAnimatedColoredShadow(initialColor, targetColor, durationMillis, alpha, borderRadius, shadowRadius, offsetY, offsetX)
}

internal fun Modifier.drawColoredShadow(
    color: Color,
    alpha: Float = 0.2f,
    borderRadius: Dp = 0.dp,
    shadowRadius: Dp = 20.dp,
    offsetY: Dp = 0.dp,
    offsetX: Dp = 0.dp
) = this.drawBehind {
    val transparentColor = android.graphics.Color.toArgb(
        color.copy(alpha = 0.0f).value.toLong()
    )
    val shadowColor = android.graphics.Color.toArgb(
        color.copy(alpha = alpha).value.toLong()
    )
    this.drawIntoCanvas {
        val paint = Paint()
        val frameworkPaint = paint.asFrameworkPaint()
        frameworkPaint.color = transparentColor
        frameworkPaint.setShadowLayer(
            shadowRadius.toPx(),
            offsetX.toPx(),
            offsetY.toPx(),
            shadowColor
        )

        it.drawRoundRect(
            0f,
            0f,
            this.size.width,
            this.size.height,
            borderRadius.toPx(),
            borderRadius.toPx(),
            paint
        )
    }
}

fun ModifierStyleScope.drawColoredShadow(
    color: Color,
    alpha: Float = 0.2f,
    borderRadius: Dp = 0.dp,
    shadowRadius: Dp = 20.dp,
    offsetY: Dp = 0.dp,
    offsetX: Dp = 0.dp
){
    modifier = modifier.drawColoredShadow(color, alpha, borderRadius, shadowRadius, offsetY, offsetX)
}*/
